package com.babyqiao.wallpaper.portal.controller;

import com.babyqiao.wallpaper.common.UnifyResult;
import com.babyqiao.wallpaper.portal.entity.WallpaperTag;
import com.babyqiao.wallpaper.portal.entity.vo.AlbumResVO;
import com.babyqiao.wallpaper.portal.service.ICategoryPageService;
import com.babyqiao.wallpaper.portal.service.IWallpaperAlbumService;
import com.babyqiao.wallpaper.portal.service.IWallpaperTagService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author QLZ
 * @date 2021/3/1
 */
@RestController
@Api(tags = "分类页接口")
@RequestMapping("/wp/category")
public class CategoryPageController {

    @Autowired
    private IWallpaperTagService tagService;

    @Autowired
    ICategoryPageService categoryPageService;

    @GetMapping("tags")
    @ApiOperation(value = "获取所有标签",httpMethod = "GET")
    @Cacheable(value = "TagContent", key = "'tag'", sync = true)
    public UnifyResult getAllTags(){
        QueryWrapper<WallpaperTag> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("gmt_modified");
        List<WallpaperTag> list = tagService.list(queryWrapper);

        return UnifyResult.success().data("result",list);
    }
    @GetMapping("albums/{current}/{limit}/new")
    @ApiOperation(value = "分页获取最新专辑",httpMethod = "GET")
    public UnifyResult getAlbumsWithNew(@ApiParam(name = "current",value = "当前页",required = true) @PathVariable long current,
                                         @ApiParam(name = "limit",value = "每页查询条数",required = true)@PathVariable long limit){
        List<AlbumResVO> albumResVOS= categoryPageService.findalbumWithNewService(current,limit);
        return UnifyResult.success().data("result",albumResVOS);
    }

    @GetMapping("albums/{current}/{limit}/hot")
    @ApiOperation(value = "分页获取热门专辑",httpMethod = "GET")
    public UnifyResult getAlbumsWithHot(@ApiParam(name = "current",value = "当前页",required = true) @PathVariable long current,
                                        @ApiParam(name = "limit",value = "每页查询条数",required = true)@PathVariable long limit){
        List<AlbumResVO> albumResVOS= categoryPageService.findalbumWithHotService(current,limit);
        return UnifyResult.success().data("result",albumResVOS);
    }

    @GetMapping("albums/{current}/{limit}/like")
    @ApiOperation(value = "分页获取人气专辑",httpMethod = "GET")
    public UnifyResult getAlbumsWithLike(@ApiParam(name = "current",value = "当前页",required = true) @PathVariable long current,
                                        @ApiParam(name = "limit",value = "每页查询条数",required = true)@PathVariable long limit){
        List<AlbumResVO> albumResVOS= categoryPageService.findalbumWithLikeService(current,limit);
        return UnifyResult.success().data("result",albumResVOS);
    }
}
